<template>
  <el-dialog title="检票" :visible.sync="dialogVisible" width="500px">
    <div v-if="info" class="text-18px">
      <template v-if="info.businessTypeId == 1 && info.status == 21">
        <!-- 过期的票类 -->
        <p>该门票的预定游玩日为: {{ info.useStartTime }}</p>
        <p
          v-if="
            info.orderProductAttribute &&
              info.orderProductAttribute.periodStartTime
          "
        >
          预定场次为: {{ info.orderProductAttribute.periodStartTime }} ~
          {{ info.orderProductAttribute.periodEndTime }}
        </p>
        <p>门票已过期，确定对该订单进行核销？</p>
      </template>
      <template v-else>
        <p>
          {{ info.orderId }} {{ info.productName }}，数量{{ info.quantity }}
        </p>
        <p>确定对该订单进行核销？</p>
      </template>
    </div>
    <span slot="footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="confirm" :loading="inRequest">
        确定
      </el-button>
    </span>
  </el-dialog>
</template>
<script>
import API from './api'
export default {
  data () {
    return {
      dialogVisible: false,
      orderId: '',
      inRequest: false,
      info: null
    }
  },
  methods: {
    open (orderId) {
      this.orderId = orderId
      this.dialogVisible = true

      API.getOrderInfo({
        orderId
      }).then(({ data }) => {
        this.info = data
      })
    },
    confirm () {
      this.inRequest = true
      API.completeOrder({
        orderId: this.orderId
      })
        .then(({ data }) => {
          this.$swal.success('操作成功')
          this.$emit('save')
          this.dialogVisible = false
          this.inRequest = false
        })
        .catch(() => {
          this.inRequest = false
        })
    }
  }
}
</script>
